home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / emacs_src_18_58.lha / emacs-18.58 / src / xdisp.c < prev    next >
C/C++ Source or Header  |  1992-07-05  |  62KB  |  2,205 lines

  1. /* Display generation from window structure and buffer text.
  2.    Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include <stdio.h>
  23. /*#include <ctype.h>*/
  24. #undef NULL
  25. #include "lisp.h"
  26. #include "window.h"
  27. #include "termchar.h"
  28. #include "dispextern.h"
  29. #include "buffer.h"
  30. #include "indent.h"
  31. #include "commands.h"
  32. #include "macros.h"
  33.  
  34. #define MAX_WIN_LINE 64
  35. static int win_line_bufpos[MAX_WIN_LINE];
  36. static int win_line_modified;
  37. static struct buffer *win_line_buffer;
  38. #define CLEAR_WIN_LINE() (win_line_buffer = 0)
  39.  
  40. #ifdef EIGHT_BIT
  41. char visible[256];        /* visible[i] is true if character i is
  42.                    displayable */
  43. #endif
  44.  
  45. extern int interrupt_input;
  46. extern int command_loop_level;
  47.  
  48. /* Nonzero means print newline before next minibuffer message.  */
  49.  
  50. int noninteractive_need_newline;
  51.  
  52. #define min(a, b) ((a) < (b) ? (a) : (b))
  53. #define max(a, b) ((a) > (b) ? (a) : (b))
  54.  
  55. /* The buffer position of the first character appearing
  56.  entirely or partially on the current screen line.
  57.  Or zero, which disables the optimization for the current screen line. */
  58. static int this_line_bufpos;
  59.  
  60. /* Number of characters past the end of this line,
  61.    including the terminating newline */
  62. static int this_line_endpos;
  63.  
  64. /* The vertical position of this screen line. */
  65. static int this_line_vpos;
  66.  
  67. /* Hpos value for start of display on this screen line.
  68.    Usually zero, but negative if first character really began
  69.    on previous line */
  70. static int this_line_start_hpos;
  71.  
  72. /* Buffer that this_line variables are describing. */
  73. static struct buffer *this_line_buffer;
  74.  
  75. /* Value of echo_area_contents when it was last acted on.
  76.   If this is nonzero, there is a message on the screen
  77.   in the minibuffer and it should be erased as soon
  78.   as it is no longer requested to appear. */
  79. char *prev_echo_area_contents;
  80.  
  81. /* Nonzero means truncate lines in all windows less wide than the screen */
  82. int truncate_partial_width_windows;
  83.  
  84. Lisp_Object Vglobal_mode_string;
  85.  
  86. /* Marker for where to display an arrow on top of the buffer text.  */
  87. Lisp_Object Voverlay_arrow_position;
  88.  
  89. /* String to display for the arrow.  */
  90. Lisp_Object Voverlay_arrow_string;
  91.  
  92. /* Values of those variables at last redisplay.  */
  93. Lisp_Object last_arrow_position, last_arrow_string;
  94.  
  95. /* If cursor motion alone moves point off screen,
  96.    Try scrolling this many lines up or down if that will bring it back.  */
  97. int scroll_step;
  98.  
  99. /* Nonzero means send various TERMCAP strings when screen is cleared.  */
  100. int reset_terminal_on_clear;
  101.  
  102. /* Nonzero if try_window_id has made blank lines at window bottom
  103.  since the last redisplay that paused */
  104. static int blank_end_of_window;
  105.  
  106. /* Number of windows showing the buffer of the selected window.
  107.    keyboard.c refers to this.  */
  108. int buffer_shared;
  109.  
  110. /* display_text_line sets these to the screen position (origin 0) of point,
  111.   whether the window is selected or not.
  112.  Set one to -1 first to determine whether point was found afterwards.  */
  113.  
  114. static int point_vpos;
  115. static int point_hpos;
  116.  
  117. int debug_end_pos;
  118.  
  119. /* Nonzero means display mode line highlighted */
  120. int mode_line_inverse_video;
  121.  
  122. struct position *display_text_line ();
  123.  
  124. /* Prompt to display in front of the minibuffer contents */
  125. char *minibuf_prompt;
  126.  
  127. /* Width in columns of current minibuffer prompt.  */
  128. int minibuf_prompt_width;
  129.  
  130. /* Message to display instead of minibuffer contents
  131.    This is what the functions error and message make,
  132.    and command echoing uses it as well.
  133.    It overrides the minibuf_prompt as well as the buffer.  */
  134. char *echo_area_contents;
  135.  
  136. /* True iff we should redraw the mode lines on the next redisplay */
  137. int update_mode_lines;
  138.  
  139. /* Smallest number of characters before the gap
  140.    at any time since last redisplay that finished.
  141.    Valid for current buffer when try_window_id can be called.  */
  142. int beg_unchanged;
  143.  
  144. /* Smallest number of characters after the gap
  145.    at any time since last redisplay that finished.
  146.    Valid for current buffer when try_window_id can be called.  */
  147. int end_unchanged;
  148.  
  149. /* MODIFF as of last redisplay that finished;
  150.  if it matches MODIFF, beg_unchanged and end_unchanged
  151.  contain no useful information */
  152. int unchanged_modified;
  153.  
  154. /* Nonzero if head_clip or tail_clip of current buffer has changed
  155.  since last redisplay that finished */
  156. int clip_changed;
  157.  
  158. /* Nonzero if window sizes or contents have changed
  159.  since last redisplay that finished */
  160. int windows_or_buffers_changed;
  161.  
  162. char *decode_mode_spec ();
  163.  
  164. DEFUN ("redraw-display", Fredraw_display, Sredraw_display, 0, 0, "",
  165.   "Clear the screen and output again what is supposed to appear on it.")
  166.   ()
  167. {
  168.   if (screen_height == 0) abort (); /* Some bug zeros some core */
  169.   if (reset_terminal_on_clear)
  170.     set_terminal_modes ();
  171.   clear_screen ();
  172.   fflush (stdout);
  173.   clear_screen_records ();
  174.   if (screen_height == 0) abort (); /* Some bug zeros some core */
  175.   windows_or_buffers_changed++;
  176.   /* Mark all windows as INaccurate,
  177.      so that every window will have its redisplay done.  */
  178.   mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 0);
  179.   if (screen_height == 0) abort (); /* Some bug zeros some core */
  180.   return Qnil;
  181. }
  182.  
  183. /* Buffer used for messages formatted by `message', and by print.  */
  184. char *message_buf;
  185.  
  186. /* Nonzero if message_buf is being used by print;
  187.    zero if being used by message.  */
  188. int message_buf_print;
  189.  
  190. /* dump an informative message to the minibuf */
  191. /* VARARGS 1 */
  192. message (m, a1, a2, a3)
  193.      char *m;
  194. {
  195.   if (noninteractive)
  196.     {
  197.       if (noninteractive_need_newline)
  198.     putchar ('\n');
  199.       noninteractive_need_newline = 0;
  200.       printf (m, a1, a2, a3);
  201.       printf ("\n");
  202.       fflush (stdout);
  203.     }
  204.   else if (FROM_KBD)
  205.     {
  206. #ifdef NO_ARG_ARRAY
  207.       int a[3];
  208.       a[0] = a1;
  209.       a[1] = a2;
  210.       a[2] = a3;
  211.  
  212.       doprnt (message_buf, screen_width, m, 3, a);
  213. #else
  214.       doprnt (message_buf, screen_width, m, 3, &a1);
  215. #endif /* NO_ARG_ARRAY */
  216.       echo_area_contents = message_buf;
  217.       message_buf_print = 0;
  218.       do {
  219.     do_pending_window_change ();
  220.     display_echo_area_contents ();
  221.     update_screen (1, 1);
  222.     do_pending_window_change ();
  223.       } while (screen_garbaged);
  224.     }
  225. }
  226.  
  227. /* Specify m, a string, as a message in the minibuf.  */
  228. message1 (m)
  229.      char *m;
  230. {
  231.   if (noninteractive)
  232.     {
  233.       if (noninteractive_need_newline)
  234.     putchar ('\n');
  235.       noninteractive_need_newline = 0;
  236.       printf ("%s\n", m);
  237.       fflush (stdout);
  238.     }
  239.   else if (FROM_KBD)
  240.     {
  241.       echo_area_contents = m;
  242.       do {
  243.     do_pending_window_change ();
  244.     display_echo_area_contents ();
  245.     update_screen (1, 1);
  246.     do_pending_window_change ();
  247.       } while (screen_garbaged);
  248.     }
  249. }
  250.  
  251. display_echo_area_contents ()
  252. {
  253.   register int vpos;
  254.  
  255.   if (screen_garbaged)
  256.     {
  257.       Fredraw_display ();
  258.       screen_garbaged = 0;
  259.     }
  260.  
  261.   if (echo_area_contents || minibuf_level == 0)
  262.     {
  263.       vpos = XFASTINT (XWINDOW (minibuf_window)->top);
  264.       get_display_line (vpos, 0);
  265.       display_string (XWINDOW (minibuf_window), vpos,
  266.               echo_area_contents ? echo_area_contents : "",
  267.               0, 0, 0, screen_width);
  268.  
  269.       /* If desired cursor location is on this line, put it at end of text */
  270.       if (cursor_vpos == vpos)
  271.     cursor_hpos = new_screen->used[vpos];
  272.     }
  273.   else if (!EQ (minibuf_window, selected_window))
  274.     windows_or_buffers_changed++;
  275.  
  276.   if (EQ (minibuf_window, selected_window))
  277.     {
  278.       this_line_bufpos = 0;
  279.       CLEAR_WIN_LINE();
  280.     }
  281.  
  282.   prev_echo_area_contents = echo_area_contents;
  283. }
  284.  
  285. /* Do a screen update, taking possible shortcuts into account.
  286.    This is the main external entry point for redisplay.
  287.  
  288.    If the last redisplay displayed an echo area message and that
  289.    message is no longer requested, we clear the echo area
  290.    or bring back the minibuffer if that is in use.
  291.  
  292.    Everyone would like to have a hook here to call eval,
  293.    but that cannot be done safely without a lot of changes elsewhere.
  294.    This can be called from signal handlers; with alarms set up;
  295.    or with synchronous processes running.
  296.    See the function `echo' in keyboard.c.
  297.    See Fcall_process; if you called it from here, it could be
  298.    entered recursively.  */
  299.  
  300. redisplay ()
  301. {
  302.   register struct window *w = XWINDOW (selected_window);
  303.   register int pause;
  304.   int inhibit_hairy_id = 0;
  305.   int must_finish = 0;
  306.   int all_windows;
  307.   register int tlbufpos, tlendpos;
  308.   struct position pos;
  309.   extern int input_pending;
  310.  
  311.   if (noninteractive)
  312.     return;
  313.  
  314.   /* Notice any pending interrupt request to change screen size.  */
  315.   do_pending_window_change ();
  316.  
  317.   if (screen_garbaged)
  318.     {
  319.       Fredraw_display ();
  320.       screen_garbaged = 0;
  321.     }
  322.  
  323.   /* Initially we have nothing to update on the screen.  */
  324.   bzero (new_screen->enable, new_screen->height);
  325.  
  326.   if (echo_area_contents != 0 || prev_echo_area_contents != 0)
  327.     {
  328.       display_echo_area_contents ();
  329.       must_finish = 1;
  330.     }
  331.  
  332.   if (windows_or_buffers_changed) CLEAR_WIN_LINE();
  333.  
  334.   if (clip_changed || windows_or_buffers_changed)
  335.     update_mode_lines++;
  336.  
  337.   /* Detect case that we need to write a star in the mode line.  */
  338.   if (XFASTINT (w->last_modified) < MODIFF
  339.       && XFASTINT (w->last_modified) <= current_buffer->save_modified)
  340.     {
  341.       w->update_mode_line = Qt;
  342.       if (buffer_shared > 1)
  343.     update_mode_lines++;
  344.     }
  345.  
  346.   all_windows = update_mode_lines || buffer_shared > 1;
  347.  
  348.   /* If specs for an arrow have changed, do thorough redisplay
  349.      to ensure we remove any arrow that should no longer exist.  */
  350.   if (Voverlay_arrow_position != last_arrow_position
  351.       || Voverlay_arrow_string != last_arrow_string)
  352.     all_windows = 1, clip_changed = 1;
  353.  
  354.   tlbufpos = this_line_bufpos;
  355.   tlendpos = this_line_endpos;
  356.   if (!all_windows && tlbufpos > 0 && NULL (w->update_mode_line)
  357.       /* Make sure recorded data applies to current buffer, etc */
  358.       && this_line_buffer == current_buffer
  359.       && current_buffer == XBUFFER (w->buffer)
  360.       && NULL (w->force_start)
  361.       /* Point must be on the line that we have info recorded about */
  362.       && point >= tlbufpos
  363.       && point <= Z - tlendpos
  364.       /* All text outside that line, including its final newline,
  365.      must be unchanged */
  366.       && (XFASTINT (w->last_modified) >= MODIFF
  367.       || (beg_unchanged >= tlbufpos - 1
  368.           && GPT >= tlbufpos
  369.           /* If selective display, can't optimize
  370.          if the changes start at the beginning of the line.  */
  371.           && ((XTYPE (current_buffer->selective_display) == Lisp_Int
  372.            && XINT (current_buffer->selective_display) > 0
  373.            ? (beg_unchanged >= tlbufpos
  374.               && GPT > tlbufpos)
  375.            : 1))
  376.           && end_unchanged >= tlendpos
  377.           && Z - GPT >= tlendpos)))
  378.     {
  379.       if (tlbufpos > BEGV && FETCH_CHAR (tlbufpos - 1) != '\n'
  380.       && (tlbufpos == ZV
  381.           || FETCH_CHAR (tlbufpos) == '\n'))
  382.     /* Former continuation line has disappeared by becoming empty */
  383.     goto cancel;
  384.       else if (XFASTINT (w->last_modified) < MODIFF
  385.            || EQ (selected_window, minibuf_window))
  386.     {
  387.       point_vpos = -1;
  388.       display_text_line (w, tlbufpos, this_line_vpos, this_line_start_hpos,
  389.                  pos_tab_offset (w, tlbufpos));
  390.       /* If line contains point, is not continued,
  391.          and ends at same distance from eob as before, we win */
  392.       if (point_vpos >= 0 && this_line_bufpos
  393.           && this_line_endpos == tlendpos)
  394.         {
  395.           /* Done by display_text_line
  396.          cursor_hpos = point_hpos;
  397.              cursor_vpos = this_line_vpos;
  398.            */
  399.           if (XFASTINT (w->width) != screen_width)
  400.         preserve_other_columns (w);
  401.           goto update;
  402.         }
  403.       else
  404.         goto cancel;
  405.     }
  406.       else if (point == XFASTINT (w->last_point))
  407.     {
  408.       if (!must_finish)
  409.         return;
  410.       goto update;
  411.     }
  412.       else
  413.     {
  414.       pos = *compute_motion (tlbufpos, 0,
  415.                 XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0,
  416.                 point, 2, - (1 << (SHORTBITS - 1)),
  417.                 XFASTINT (w->width) - 1
  418.                 - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width),
  419.                 XINT (w->hscroll),
  420.                  pos_tab_offset (w, tlbufpos));
  421.       if (pos.vpos < 1)
  422.         {
  423.           cursor_hpos = max (XFASTINT (w->left), pos.hpos);
  424.           cursor_vpos = this_line_vpos;
  425.           goto update;
  426.         }
  427.       else
  428.         goto cancel;
  429.     }
  430.     cancel:
  431.       /* Text changed drastically or point moved off of line */
  432.       cancel_line (this_line_vpos);
  433.     }
  434.  
  435.   this_line_bufpos = 0;
  436.  
  437.   if (all_windows)
  438.     redisplay_all_windows ();
  439.   else
  440.     {
  441.       redisplay_window (selected_window, 1);
  442.       if (XFASTINT (w->width) != screen_width)
  443.     preserve_other_columns (w);
  444.     }
  445.  
  446. update: 
  447.   /* Prevent various kinds of signals during display update.
  448.      stdio is not robust about handling signals,
  449.      which can cause an apparent I/O error.  */
  450.   if (interrupt_input)
  451.     unrequest_sigio ();
  452.   stop_polling ();
  453.  
  454.   pause = update_screen (0, 0);
  455.  
  456.   /* If screen does not match, prevent doing single-line-update next time.
  457.      Also, don't forget to check every line to update the arrow.  */
  458.   if (pause)
  459.     {
  460.       CLEAR_WIN_LINE();
  461.       this_line_bufpos = 0;
  462.       if (!NULL (last_arrow_position))
  463.     {
  464.       last_arrow_position = Qt;
  465.       last_arrow_string = Qt;
  466.     }
  467.       /* If we pause after scrolling, some lines in PhysScreen may be null
  468.      and then preserve_other_columns won't be able to preserve all
  469.      the vertical-bar separators.  So avoid using it in that case.  */
  470.       if (XFASTINT (w->width) != screen_width)
  471.     update_mode_lines = 1;
  472.     }
  473.  
  474.   /* Now text on screen agrees with windows, so
  475.      put info into the windows for partial redisplay to follow */
  476.  
  477.   if (!pause)
  478.     {
  479.       struct buffer *b = XBUFFER (w->buffer);
  480.  
  481.       blank_end_of_window = 0;
  482.       clip_changed = 0;
  483.       unchanged_modified = BUF_MODIFF (b);
  484.       beg_unchanged = BUF_GPT (b) - BUF_BEG (b);
  485.       end_unchanged = BUF_Z (b) - BUF_GPT (b);
  486.  
  487.       XFASTINT (w->last_point) = BUF_PT (b);
  488.       XFASTINT (w->last_point_x) = cursor_hpos;
  489.       XFASTINT (w->last_point_y) = cursor_vpos;
  490.  
  491.       if (all_windows)
  492.     mark_window_display_accurate (XWINDOW (minibuf_window)->prev, 1);
  493.       else
  494.     {
  495.       w->update_mode_line = Qnil;
  496.       XFASTINT (w->last_modified) = BUF_MODIFF (b);
  497.       w->window_end_valid = Qt;
  498.       last_arrow_position = Voverlay_arrow_position;
  499.       last_arrow_string = Voverlay_arrow_string;
  500.     }
  501.       update_mode_lines = 0;
  502.       windows_or_buffers_changed = 0;
  503.     }
  504.  
  505.   /* Start SIGIO interrupts coming again.
  506.      Having them off during the code above
  507.      makes it less likely one will discard output,
  508.      but not impossible, since there might be stuff
  509.      in the system buffer here.
  510.      But it is much hairier to try to do anything about that.  */
  511.  
  512.   if (interrupt_input)
  513.     request_sigio ();
  514.   start_polling ();
  515.  
  516.   do_pending_window_change ();
  517.  
  518.   if (screen_garbaged)
  519.     redisplay ();
  520. }
  521.  
  522. /* Redisplay, but leave alone any recent echo area message
  523.    unless another message has been requested in its place.  */
  524.  
  525. redisplay_preserve_echo_area ()
  526. {
  527.   if (echo_area_contents == 0 && prev_echo_area_contents != 0)
  528.     {
  529.       echo_area_contents = prev_echo_area_contents;
  530.       redisplay ();
  531.       echo_area_contents = 0;
  532.     }
  533.   else
  534.     redisplay ();
  535. }
  536.  
  537. mark_window_display_accurate (window, flag)
  538.      Lisp_Object window;
  539.      int flag;
  540. {
  541.   register struct window *w;
  542.  
  543.   for (;!NULL (window); window = w->next)
  544.     {
  545.       w = XWINDOW (window);
  546.  
  547.       if (!NULL (w->buffer))
  548.     XFASTINT (w->last_modified)
  549.       = !flag ? 0 : BUF_MODIFF (XBUFFER (w->buffer));
  550.       w->window_end_valid = Qt;
  551.       w->update_mode_line = Qnil;
  552.  
  553.       if (!NULL (w->vchild))
  554.     mark_window_display_accurate (w->vchild, flag);
  555.       if (!NULL (w->hchild))
  556.     mark_window_display_accurate (w->hchild, flag);
  557.     }
  558.  
  559.   if (flag)
  560.     {
  561.       last_arrow_position = Voverlay_arrow_position;
  562.       last_arrow_string = Voverlay_arrow_string;
  563.     }
  564.   else
  565.     {
  566.       /* t is unequal to any useful value of Voverlay_arrow_... */
  567.       last_arrow_position = Qt;
  568.       last_arrow_string = Qt;
  569.     }
  570. }
  571.  
  572. int do_id = 1;
  573.  
  574. /* Do full redisplay of one or all windows.
  575.   This does not include updating the screen;
  576.   just generating lines to pass to update_screen.  */
  577.  
  578. /* Entry point to redisplay all windows */
  579.  
  580. redisplay_all_windows ()
  581. {
  582.   buffer_shared = 0;
  583.  
  584.   redisplay_windows (XWINDOW (minibuf_window)->prev);
  585. }
  586.  
  587. redisplay_windows (window)
  588.      Lisp_Object window;
  589. {
  590.   for (; !NULL (window); window = XWINDOW (window)->next)
  591.     redisplay_window (window, 0);
  592. }
  593.  
  594. redisplay_window (window, just_this_one)
  595.      Lisp_Object window;
  596.      int just_this_one;
  597. {
  598.   register struct window *w = XWINDOW (window);
  599.   int height;
  600.   struct buffer *old = current_buffer;
  601.   register int width = XFASTINT (w->width) - 1
  602.     - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width);
  603.   register int startp;
  604.   register int hscroll = XINT (w->hscroll);
  605.   struct position pos;
  606.   int opoint;
  607.   int tem;
  608.  
  609.   if (screen_height == 0) abort (); /* Some bug zeros some core */
  610.  
  611.   /* If this is a combination window, do its children; that's all.  */
  612.  
  613.   if (!NULL (w->vchild))
  614.     {
  615.       redisplay_windows (w->vchild);
  616.       return;
  617.     }
  618.   if (!NULL (w->hchild))
  619.     {
  620.       redisplay_windows (w->hchild);
  621.       return;
  622.     }
  623.   if (NULL (w->buffer))
  624.     abort ();
  625.  
  626.   if (update_mode_lines)
  627.     w->update_mode_line = Qt;
  628.  
  629.   /* Otherwise set up data on this window; select its buffer and point value */
  630.  
  631.   height = XFASTINT (w->height);
  632.   if (w != XWINDOW (minibuf_window))
  633.     height--;
  634.   else if (echo_area_contents)
  635.     return 0;
  636.  
  637.   current_buffer = XBUFFER (w->buffer);
  638.  
  639.   if (!just_this_one
  640.       && current_buffer == XBUFFER (XWINDOW (selected_window)->buffer))
  641.     buffer_shared++;
  642.  
  643.   /* Go temporarily to where point is in the window being displayed.
  644.      We will restore point at the end.  */
  645.   opoint = point;
  646.   if (!EQ (window, selected_window))
  647.     {
  648.       SET_PT (marker_position (w->pointm));
  649.       if (point < BEGV)
  650.     point = BEGV;
  651.       else if (point > ZV)
  652.     point = ZV;
  653.     }
  654.  
  655.   /* If window-start is screwed up, choose a new one.  */
  656.  
  657.   if (XMARKER (w->start)->buffer != current_buffer)
  658.     goto recenter;
  659.  
  660.   startp = marker_position (w->start);
  661.  
  662.   /* Handle case where place to start displaying has been specified */
  663.  
  664.   if (!NULL (w->force_start))
  665.     {
  666.       w->update_mode_line = Qt;
  667.       w->force_start = Qnil;
  668.       XFASTINT (w->last_modified) = 0;
  669.       try_window (window, startp);
  670.       if (point_vpos < 0)
  671.     {
  672.       /* If point does not appear, move point so it does appear */
  673.       pos = *compute_motion (startp, 0,
  674.                 ((EQ (window, minibuf_window) && startp == 1)
  675.                  ? minibuf_prompt_width : 0)
  676.                 +
  677.                 (hscroll ? 1 - hscroll : 0),
  678.                 ZV, height / 2,
  679.                 - (1 << (SHORTBITS - 1)),
  680.                 width, hscroll, pos_tab_offset (w, startp));
  681.       SET_PT (pos.bufpos);
  682.       if (w != XWINDOW (selected_window))
  683.         Fset_marker (w->pointm, make_number (point), Qnil);
  684.       else
  685.         /* We want to change point permanently,
  686.            so don't restore the old value.  */
  687.         opoint = point;
  688.  
  689.       if (EQ (window, selected_window))
  690.         {
  691.           cursor_hpos = max (0, pos.hpos) + XFASTINT (w->left);
  692.           cursor_vpos = pos.vpos + XFASTINT (w->top);
  693.         }
  694.     }
  695.       goto done;
  696.     }
  697.  
  698.   /* Handle case where text has not changed, only point,
  699.      and it has not moved off the screen */
  700.  
  701.   /* This code is not used for minibuffer for the sake of
  702.      the case of redisplaying to replace an echo area message;
  703.      since in that case the minibuffer contents per se are usually unchanged.
  704.      This code is of no real use in the minibuffer since
  705.      the handling of this_line_bufpos, etc.,
  706.      in redisplay handles the same cases.  */
  707.  
  708.   if (XFASTINT (w->last_modified) >= MODIFF
  709.       && point >= startp && !clip_changed
  710.       && (just_this_one || XFASTINT (w->width) == screen_width)
  711.       && !EQ (window, minibuf_window))
  712.     {
  713.       int *wlb;
  714.       int line, best_startp, best_vpos;
  715.  
  716.       best_startp = startp; best_vpos = 0;
  717.       if (win_line_buffer && BUF_MODIFF(win_line_buffer) > win_line_modified)
  718.       CLEAR_WIN_LINE();
  719.       if (current_buffer == win_line_buffer && current_buffer == XBUFFER (w->buffer))
  720.         {
  721.       /* Try & find line to start from */
  722.       wlb = win_line_bufpos; line = 0;
  723.       while (line < MAX_WIN_LINE)
  724.         {
  725.           if (*wlb && point > *wlb && *wlb > best_startp)
  726.             {
  727.           best_startp = *wlb;
  728.           best_vpos = line;
  729.             }
  730.           line++; wlb++;
  731.         }
  732.         }
  733.       pos = *compute_motion (best_startp, best_vpos, (hscroll ? 1 - hscroll : 0),
  734.                 point, height + 1, 10000, width, hscroll,
  735.                 pos_tab_offset (w, best_startp));
  736.  
  737.       if (pos.vpos < height)
  738.     {
  739.       /* Ok, point is still on screen */
  740.       if (w == XWINDOW (selected_window))
  741.         {
  742.           /* These variables are supposed to be origin 1 */
  743.           cursor_hpos = max (0, pos.hpos) + XFASTINT (w->left);
  744.           cursor_vpos = pos.vpos + XFASTINT (w->top);
  745.         }
  746. /* This doesn't do the trick, because if a window to the right of
  747.  this one must be redisplayed, this does nothing because there
  748.  is nothing in DesiredScreen yet, and then the other window is
  749.  redisplayed, making likes that are empty in this window's columns.
  750.       if (XFASTINT (w->width) != screen_width)
  751.         preserve_my_columns (w);
  752. */
  753.       goto done;
  754.     }
  755.       /* Don't bother trying redisplay with same start;
  756.     we already know it will lose */
  757.     }
  758.   /* If current starting point was originally the beginning of a line
  759.      but no longer is, find a new starting point.  */
  760.   else if (!NULL (w->start_at_line_beg)
  761.        && !(startp == BEGV
  762.         || FETCH_CHAR (startp - 1) == '\n'))
  763.     {
  764.       goto recenter;
  765.     }
  766.   else if (just_this_one && !EQ (window, minibuf_window)
  767.        && point >= startp
  768.        && XFASTINT (w->last_modified)
  769.        && ! EQ (w->window_end_valid, Qnil)
  770.        && do_id && !clip_changed
  771.        && !blank_end_of_window
  772.        && XFASTINT (w->width) == screen_width
  773.        && EQ (last_arrow_position, Voverlay_arrow_position)
  774.        && EQ (last_arrow_string, Voverlay_arrow_string)
  775.        && (tem = try_window_id (selected_window))
  776.        && tem != -2)
  777.     {
  778.       /* tem > 0 means success.  tem == -1 means choose new start.
  779.      tem == -2 means try again with same start,
  780.       and nothing but whitespace follows the changed stuff.
  781.      tem == 0 means try again with same start.  */
  782.       if (tem > 0)
  783.     {
  784.       goto done;
  785.     }
  786.     }
  787.   else if (startp >= BEGV && startp <= ZV
  788.        /* Avoid starting display at end of buffer! */
  789.        && (startp < ZV || startp == BEGV
  790.            || (XFASTINT (w->last_modified) >= MODIFF)))
  791.     {
  792.       /* Try to redisplay starting at same place as before */
  793.       /* If point has not moved off screen, accept the results */
  794.       try_window (window, startp);
  795.       if (point_vpos >= 0)
  796.     goto done;
  797.       else
  798.     cancel_my_columns (w);
  799.     }
  800.  
  801.   XFASTINT (w->last_modified) = 0;
  802.   w->update_mode_line = Qt;
  803.  
  804.   /* Try to scroll by specified few lines */
  805.  
  806.   if (scroll_step && !clip_changed)
  807.     {
  808.       if (point > startp)
  809.     {
  810.       pos = *vmotion (Z - XFASTINT (w->window_end_pos),
  811.               scroll_step, width, hscroll, window);
  812.       if (pos.vpos >= height)
  813.         goto scroll_fail;
  814.     }
  815.  
  816.       pos = *vmotion (startp, point < startp ? - scroll_step : scroll_step,
  817.               width, hscroll, window);
  818.  
  819.       if (point >= pos.bufpos)
  820.     {
  821.       try_window (window, pos.bufpos);
  822.       if (point_vpos >= 0)
  823.         goto done;
  824.       else
  825.         cancel_my_columns (w);
  826.     }
  827.     scroll_fail: ;
  828.     }
  829.  
  830.   /* Finally, just choose place to start which centers point */
  831.  
  832. recenter:
  833.   pos = *vmotion (point, - height / 2, width, hscroll, window);
  834.   try_window (window, pos.bufpos);
  835.  
  836.   startp = marker_position (w->start);
  837.   w->start_at_line_beg = 
  838.     (startp == BEGV || FETCH_CHAR (startp - 1) == '\n') ? Qt : Qnil;
  839.  
  840. done:
  841.   /* If window not full width, must redo its mode line
  842.      if the window to its side is being redone */
  843.   if ((!NULL (w->update_mode_line)
  844.        || (!just_this_one && width < screen_width - 1))
  845.       && !EQ (window, minibuf_window))
  846.     display_mode_line (w);
  847.  
  848.   SET_PT (opoint);
  849.   current_buffer = old;
  850. }
  851.  
  852. /* Do full redisplay on one window,
  853.    starting at position `pos'.  */
  854.  
  855. try_window (window, pos)
  856.      Lisp_Object window;
  857.      register int pos;
  858. {
  859.   register struct window *w = XWINDOW (window);
  860.   register int height = XFASTINT (w->height) - !EQ (window, minibuf_window);
  861.   register int vpos = XFASTINT (w->top);
  862.   register int last_text_vpos = vpos;
  863.   int tab_offset = pos_tab_offset (w, pos);
  864.  
  865.   struct position val;
  866.  
  867.   if (XBUFFER(w->buffer) == win_line_buffer) CLEAR_WIN_LINE();
  868.  
  869.   Fset_marker (w->start, make_number (pos), Qnil);
  870.  
  871.   point_vpos = -1;
  872.   val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
  873.  
  874.   while (--height >= 0)
  875.     {
  876.       val = *display_text_line (w, pos, vpos, val.hpos, tab_offset);
  877.       tab_offset += XFASTINT (w->width) - 1;
  878.       if (val.vpos) tab_offset = 0;
  879.       vpos++;
  880.       if (pos != val.bufpos)
  881.     last_text_vpos
  882.       /* Next line, unless prev line ended in end of buffer with no cr */
  883.       = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
  884.       pos = val.bufpos;
  885.     }
  886.  
  887.   /* If last line is continued in middle of character,
  888.      include the split character in the text considered on the screen */
  889.   if (val.hpos < (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0))
  890.     pos++;
  891.  
  892.   /* Say where last char on screen will be, once redisplay is finished.  */
  893.   XFASTINT (w->window_end_pos) = Z - pos;
  894.   XFASTINT (w->window_end_vpos) = last_text_vpos - XFASTINT (w->top);
  895.   /* But that is not valid info until redisplay finishes.  */
  896.   w->window_end_valid = Qnil;
  897. }
  898.  
  899. /* Try to redisplay when buffer is modified locally,
  900.  computing insert/delete line to preserve text outside
  901.  the bounds of the changes.
  902.  Return 1 if successful, 0 if if cannot tell what to do,
  903.  or -1 to tell caller to find a new window start,
  904.  or -2 to tell caller to do normal redisplay with same window start.  */
  905.  
  906. static struct position debug_bp, debug_ep, debug_xp, debug_pp;
  907. static int debug_start_vpos, debug_stop_vpos, debug_scroll_amount;
  908. static int debug_dont_scroll;
  909.  
  910. try_window_id (window)
  911.      Lisp_Object window;
  912. {
  913.   int pos;
  914.   register struct window *w = XWINDOW (window);
  915.   register int height = XFASTINT (w->height) - !EQ (window, minibuf_window);
  916.   int top = XFASTINT (w->top);
  917.   int start = marker_position (w->start);
  918.   int width = XFASTINT (w->width) - 1
  919.     - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width);
  920.   int hscroll = XINT (w->hscroll);
  921.   int lmargin = hscroll > 0 ? 1 - hscroll : 0;
  922.   register int vpos;
  923.   register int i, tem;
  924.   int last_text_vpos = 0;
  925.   int stop_vpos;
  926.  
  927.   struct position val, bp, ep, xp, pp;
  928.   int scroll_amount = 0;
  929.   int delta;
  930.   int tab_offset, epto;
  931.  
  932.   if (XBUFFER(w->buffer) == win_line_buffer) CLEAR_WIN_LINE();
  933.  
  934.   if (GPT - BEG < beg_unchanged)
  935.     beg_unchanged = GPT - BEG;
  936.   if (Z - GPT < end_unchanged)
  937.     end_unchanged = Z - GPT;
  938.  
  939.   if (beg_unchanged + 1 < start)
  940.     return 0;            /* Give up if changes go above top of window */
  941.  
  942.   /* Find position before which nothing is changed.  */
  943.   bp = *compute_motion (start, 0, lmargin,
  944.             beg_unchanged + 1, height + 1, 0, width, hscroll,
  945.             pos_tab_offset (w, start));
  946.   if (bp.vpos >= height)
  947.     {
  948.       if (point < bp.bufpos && !bp.contin)
  949.     {
  950.       /* All changes are below the screen, and point is on the screen.
  951.          We don't need to change the screen at all.
  952.          But we need to update window_end_pos to account for
  953.          any change in buffer size.  */
  954.       bp = *compute_motion (start, 0, lmargin,
  955.                 Z, height, 0,
  956.                 width, hscroll, pos_tab_offset (w, start));
  957.       XFASTINT (w->window_end_vpos) = height;
  958.       XFASTINT (w->window_end_pos) = Z - bp.bufpos;
  959.       return 1;
  960.     }
  961.       return 0;
  962.     }
  963.  
  964.   vpos = bp.vpos;
  965.  
  966.   /* Find beginning of that screen line.  Must display from there.  */
  967.   bp = *vmotion (bp.bufpos, 0, width, hscroll, window);
  968.  
  969.   pos = bp.bufpos;
  970.   val.hpos = lmargin;
  971.   if (pos < start)
  972.     return -1;
  973.  
  974.   /* If about to start displaying at the beginning of a continuation line,
  975.      really start with previous screen line, in case it was not
  976.      continued when last redisplayed */
  977.   if ((bp.contin && bp.bufpos - 1 == beg_unchanged && vpos > 0)
  978.       ||
  979.       /* Likewise if we have to worry about selective display.  */
  980.       (XTYPE (current_buffer->selective_display) == Lisp_Int
  981.        && XINT (current_buffer->selective_display) > 0
  982.        && bp.bufpos - 1 == beg_unchanged && vpos > 0))
  983.     {
  984.       bp = *vmotion (bp.bufpos, -1, width, hscroll, window);
  985.       --vpos;
  986.       pos = bp.bufpos;
  987.     }
  988.  
  989.   if (bp.contin && bp.hpos != lmargin)
  990.     {
  991.       val.hpos = bp.prevhpos - width + lmargin;
  992.       pos--;
  993.     }
  994.  
  995.   bp.vpos = vpos;
  996.  
  997.   /* Find first visible newline after which no more is changed.  */
  998.   tem = find_next_newline (Z - max (end_unchanged, Z - ZV),
  999.                1);
  1000.   if (XTYPE (current_buffer->selective_display) == Lisp_Int
  1001.       && XINT (current_buffer->selective_display) > 0)
  1002.     while (tem < ZV - 1
  1003.        && (position_indentation (tem)
  1004.            >= XINT (current_buffer->selective_display)))
  1005.       tem = find_next_newline (tem, 1);
  1006.  
  1007.   /* Compute the cursor position after that newline.  */
  1008.   ep = *compute_motion (pos, vpos, val.hpos, tem,
  1009.             height, - (1 << (SHORTBITS - 1)),
  1010.             width, hscroll, pos_tab_offset (w, bp.bufpos));
  1011.  
  1012.   /* If changes reach past the text available on the screen,
  1013.      just display rest of screen.  */
  1014.   if (ep.bufpos > Z - XFASTINT (w->window_end_pos))
  1015.     stop_vpos = height;
  1016.   else
  1017.     stop_vpos = ep.vpos;
  1018.  
  1019.   /* If no newline before ep, the line ep is on includes some changes
  1020.      that must be displayed.  Make sure we don't stop before it.  */
  1021.   /* Also, if changes reach all the way until ep.bufpos,
  1022.      it is possible that something was deleted after the
  1023.      newline before it, so the following line must be redrawn. */
  1024.   if (stop_vpos == ep.vpos
  1025.       && (ep.bufpos == BEGV
  1026.       || FETCH_CHAR (ep.bufpos - 1) != '\n'
  1027.       || ep.bufpos == Z - end_unchanged))
  1028.     stop_vpos = ep.vpos + 1;
  1029.  
  1030.   point_vpos = -1;
  1031.   debug_dont_scroll = 0;
  1032.  
  1033.   /* If changes do not reach to bottom of window,
  1034.      figure out how much to scroll the rest of the window */
  1035.   if (stop_vpos < height)
  1036.     {
  1037.       /* Now determine how far up or down the rest of the window has moved */
  1038.       epto = pos_tab_offset (w, ep.bufpos);
  1039.       xp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
  1040.                 Z - XFASTINT (w->window_end_pos),
  1041.                 10000, 0, width, hscroll, epto);
  1042.       scroll_amount = xp.vpos - XFASTINT (w->window_end_vpos);
  1043.  
  1044.       /* Is everything on screen below the changes whitespace?
  1045.      If so, no scrolling is really necessary.  */
  1046.       for (i = ep.bufpos; i < xp.bufpos; i++)
  1047.     {
  1048.       tem = FETCH_CHAR (i);
  1049.       if (tem != ' ' && tem != '\n' && tem != '\t')
  1050.         break;
  1051.     }
  1052.       if (i == xp.bufpos)
  1053.     return -2;
  1054.  
  1055.       XFASTINT (w->window_end_vpos) += scroll_amount;
  1056.  
  1057.       /* Before doing any scrolling, verify that point will be on screen. */
  1058.       if (point > ep.bufpos && !(point <= xp.bufpos && xp.bufpos < height))
  1059.     {
  1060.       if (point <= xp.bufpos)
  1061.         {
  1062.           pp = *compute_motion (ep.bufpos, ep.vpos, ep.hpos,
  1063.                     point, height, - (1 << (SHORTBITS - 1)),
  1064.                     width, hscroll, epto);
  1065.         }
  1066.       else
  1067.         {
  1068.           pp = *compute_motion (xp.bufpos, xp.vpos, xp.hpos,
  1069.                     point, height, - (1 << (SHORTBITS - 1)),
  1070.                     width, hscroll, pos_tab_offset (w, xp.bufpos));
  1071.         }
  1072.       if (pp.bufpos < point || pp.vpos == height)
  1073.         return 0;
  1074.       point_vpos = pp.vpos + top;
  1075.       point_hpos = pp.hpos + XFASTINT (w->left);
  1076.     }
  1077.  
  1078.       if (stop_vpos - scroll_amount >= height
  1079.       || ep.bufpos == xp.bufpos)
  1080.     {
  1081.       if (scroll_amount < 0)
  1082.         stop_vpos -= scroll_amount;
  1083.       scroll_amount = 0;
  1084.       debug_dont_scroll = 1;
  1085.       /* In this path, we have altered window_end_vpos
  1086.          and not left it negative.
  1087.          We must make sure that, in case display is preempted
  1088.          before the screen changes to reflect what we do here,
  1089.          further updates will not come to try_window_id
  1090.          and assume the screen and window_end_vpos match.  */
  1091.       blank_end_of_window = 1;
  1092.     }
  1093.       else if (!scroll_amount)
  1094.     {}
  1095.       else if (bp.bufpos == Z - end_unchanged)
  1096.     {
  1097.       /* If reprinting everything is nearly as fast as scrolling,
  1098.          don't bother scrolling.  Can happen if lines are short.  */
  1099.       if (scroll_cost (bp.vpos + top - scroll_amount,
  1100.                top + height - max (0, scroll_amount),
  1101.                scroll_amount)
  1102.           > xp.bufpos - bp.bufpos - 20)
  1103.         /* Return "try normal display with same window-start."
  1104.            Too bad we can't prevent further scroll-thinking.  */
  1105.         return -2;
  1106.       /* If pure deletion, scroll up as many lines as possible.
  1107.          In common case of killing a line, this can save the
  1108.          following line from being overwritten by scrolling
  1109.          and therefore having to be redrawn.  */
  1110.       tem = scroll_screen_lines (bp.vpos + top - scroll_amount,
  1111.                      top + height - max (0, scroll_amount),
  1112.                      scroll_amount);
  1113.       if (!tem) stop_vpos = height;
  1114.     }
  1115.       else if (scroll_amount)
  1116.     {
  1117.       /* If reprinting everything is nearly as fast as scrolling,
  1118.          don't bother scrolling.  Can happen if lines are short.  */
  1119.       /* Note that if scroll_amount > 0, xp.bufpos - bp.bufpos is an
  1120.          overestimate of cost of reprinting, since xp.bufpos
  1121.          would end up below the bottom of the window.  */
  1122.       if (scroll_cost (ep.vpos + top - scroll_amount,
  1123.                top + height - max (0, scroll_amount),
  1124.                scroll_amount)
  1125.           > xp.bufpos - ep.bufpos - 20)
  1126.         /* Return "try normal display with same window-start."
  1127.            Too bad we can't prevent further scroll-thinking.  */
  1128.         return -2;
  1129.       tem = scroll_screen_lines (ep.vpos + top - scroll_amount,
  1130.                      top + height - max (0, scroll_amount),
  1131.                      scroll_amount);
  1132.       if (!tem) stop_vpos = height;
  1133.     }
  1134.     }
  1135.  
  1136.   debug_scroll_amount = scroll_amount;
  1137.   debug_bp = bp;
  1138.   debug_ep = ep;
  1139.   debug_xp = xp;
  1140.   debug_pp = pp;
  1141.  
  1142.   /* In any case, do not display past bottom of window */
  1143.   if (stop_vpos >= height)
  1144.     {
  1145.       stop_vpos = height;
  1146.       scroll_amount = 0;
  1147.     }
  1148.  
  1149.   debug_stop_vpos = stop_vpos;
  1150.   debug_start_vpos = vpos;
  1151.  
  1152.   /* Handle case where pos is before w->start --
  1153.      can happen if part of line had been clipped and is not clipped now */
  1154.   if (vpos == 0 && pos < marker_position (w->start))
  1155.     Fset_marker (w->start, make_number (pos), Qnil);
  1156.  
  1157.   /* Redisplay the lines where the text was changed */
  1158.   last_text_vpos = vpos;
  1159.   tab_offset = pos_tab_offset (w, pos);
  1160.   if (val.hpos + hscroll - (hscroll > 0) < 0)
  1161.     tab_offset += XFASTINT (w->width) - 1;
  1162.   while (vpos < stop_vpos)
  1163.     {
  1164.       val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
  1165.       tab_offset += XFASTINT (w->width) - 1;
  1166.       if (val.vpos) tab_offset = 0;
  1167.       if (pos != val.bufpos)
  1168.     last_text_vpos
  1169.       /* Next line, unless prev line ended in end of buffer with no cr */
  1170.         = vpos - (val.vpos && FETCH_CHAR (val.bufpos - 1) != '\n');
  1171.       pos = val.bufpos;
  1172.     }
  1173.  
  1174.   /* There are two cases:
  1175.      1) we have displayed down to the bottom of the window
  1176.      2) we have scrolled lines below stop_vpos by scroll_amount  */
  1177.  
  1178.   if (vpos == height)
  1179.     {
  1180.       /* If last line is continued in middle of character,
  1181.      include the split character in the text considered on the screen */
  1182.       if (val.hpos < lmargin)
  1183.     val.bufpos++;
  1184.       XFASTINT (w->window_end_vpos) = last_text_vpos;
  1185.       XFASTINT (w->window_end_pos) = Z - val.bufpos;
  1186.     }
  1187.  
  1188.   /* If scrolling made blank lines at window bottom,
  1189.      redisplay to fill those lines */
  1190.   if (scroll_amount < 0)
  1191.     {
  1192.       vpos = xp.vpos;
  1193.       pos = xp.bufpos;
  1194.       val.hpos = lmargin;
  1195.       if (pos == ZV)
  1196.     vpos = height + scroll_amount;
  1197.       else if (xp.contin && xp.hpos != lmargin)
  1198.     {
  1199.       val.hpos = xp.prevhpos - width + lmargin;
  1200.       pos--;
  1201.     }
  1202.  
  1203.       blank_end_of_window = 1;
  1204.       tab_offset = pos_tab_offset (w, pos);
  1205.       if (val.hpos < 0)
  1206.     tab_offset += XFASTINT (w->width) - 1;
  1207.  
  1208.       while (vpos < height)
  1209.     {
  1210.       val = *display_text_line (w, pos, top + vpos++, val.hpos, tab_offset);
  1211.       tab_offset += XFASTINT (w->width) - 1;
  1212.       if (val.vpos) tab_offset = 0;
  1213.       pos = val.bufpos;
  1214.     }
  1215.  
  1216.       /* Here is a case where display_text_line sets point_vpos wrong.
  1217.      Make it be fixed up, below.  */
  1218.       if (xp.bufpos == ZV
  1219.       && xp.bufpos == point)
  1220.     point_vpos = -1;
  1221.     }
  1222.  
  1223.   /* Attempt to adjust end-of-text positions to new bottom line */
  1224.   if (scroll_amount)
  1225.     {
  1226.       delta = height - xp.vpos;
  1227.       if (delta < 0
  1228.       || (delta > 0 && xp.bufpos < ZV)
  1229.       || (delta == 0 && xp.hpos))
  1230.     {
  1231.       val = *vmotion (Z - XFASTINT (w->window_end_pos),
  1232.               delta, width, hscroll, window);
  1233.       XFASTINT (w->window_end_pos) = Z - val.bufpos;
  1234.       XFASTINT (w->window_end_vpos) += val.vpos;
  1235.     }
  1236.     }
  1237.  
  1238.   w->window_end_valid = Qnil;
  1239.  
  1240.   /* If point was not in a line that was displayed, find it */
  1241.   if (point_vpos < 0)
  1242.     {
  1243.       val = *compute_motion (start, 0, lmargin, point, 10000, 10000,
  1244.                  width, hscroll, pos_tab_offset (w, start));
  1245.       /* Admit failure if point is off screen now */
  1246.       if (val.vpos >= height)
  1247.     {
  1248.       for (vpos = 0; vpos < height; vpos++)
  1249.         cancel_line (vpos + top);
  1250.       return 0;
  1251.     }
  1252.       point_vpos = val.vpos + top;
  1253.       point_hpos = val.hpos + XFASTINT (w->left);
  1254.     }
  1255.  
  1256.   cursor_hpos = max (0, point_hpos);
  1257.   cursor_vpos = point_vpos;
  1258.  
  1259.   if (debug_end_pos)
  1260.     {
  1261.       val = *compute_motion (start, 0, lmargin, ZV,
  1262.                  height, - (1 << (SHORTBITS - 1)),
  1263.                  width, hscroll, pos_tab_offset (w, start));
  1264.       if (val.vpos != XFASTINT (w->window_end_vpos))
  1265.     abort ();
  1266.       if (XFASTINT (w->window_end_pos) != Z - val.bufpos)
  1267.     abort ();
  1268.     }
  1269.  
  1270.   return 1;
  1271. }
  1272.  
  1273. /* Display one line of window w, starting at position `start' in w's buffer.
  1274.  Display starting at horizontal position `hpos',
  1275.   which is normally zero or negative.
  1276.   A negative value causes output up to hpos = 0 to be discarded.
  1277.   This is done for negative hscroll, or when this is a continuation line
  1278.   and the continuation occurred in the middle of a multi-column character.
  1279.  
  1280.  `taboffset' is an offset for ostensible hpos, used in tab stop calculations.
  1281.  
  1282.  Display on position `vpos' on the screen.  (origin 0).
  1283.  
  1284.  Returns a `struct position' giving character to start next line with
  1285.  and where to display it, including a zero or negative hpos.
  1286.  The vpos field is not really a vpos; it is 1 unless the line is continued */
  1287.  
  1288. struct position val_display_text_line;
  1289.  
  1290. struct position *
  1291. display_text_line (w, start, vpos, hpos, taboffset)
  1292.      struct window *w;
  1293.      int start;
  1294.      int vpos;
  1295.      int hpos;
  1296.      int taboffset;
  1297. {
  1298.   register int pos = start;
  1299.   register int c;
  1300.   register unsigned char *p1;
  1301.   int end;
  1302.   register int pause;
  1303.   register unsigned char *p;
  1304.   unsigned char *endp;
  1305.   register unsigned char *startp;
  1306.   register unsigned char *p1prev;
  1307.   int tab_width = XINT (current_buffer->tab_width);
  1308.   int ctl_arrow = !NULL (current_buffer->ctl_arrow);
  1309.   int width = XFASTINT (w->width) - 1
  1310.     - (XFASTINT (w->width) + XFASTINT (w->left) != screen_width);
  1311.   struct position val;
  1312.   int lastpos;
  1313.   int invis;
  1314.   int hscroll = XINT (w->hscroll);
  1315.   int truncate = hscroll
  1316.     || (truncate_partial_width_windows
  1317.     && XFASTINT (w->width) < screen_width)
  1318.     || !NULL (current_buffer->truncate_lines);
  1319.   int selective
  1320.     = XTYPE (current_buffer->selective_display) == Lisp_Int
  1321.       ? XINT (current_buffer->selective_display)
  1322.     : !NULL (current_buffer->selective_display) ? -1 : 0;
  1323.   int selective_e = selective && !NULL (current_buffer->selective_display_ellipses);
  1324.  
  1325.   hpos += XFASTINT (w->left);
  1326.   get_display_line (vpos, XFASTINT (w->left));
  1327.   if (tab_width <= 0 || tab_width > 20) tab_width = 8;
  1328.  
  1329.   if (w == XWINDOW (minibuf_window) && start == 1
  1330.       && vpos == XFASTINT (w->top))
  1331.     {
  1332.       if (minibuf_prompt)
  1333.     hpos = display_string (w, vpos, minibuf_prompt, hpos,
  1334.                    !truncate ? '\\' : '$', -1, -1);
  1335.       minibuf_prompt_width = hpos;
  1336.     }
  1337.  
  1338.   p1 = new_screen->contents[vpos] + hpos;
  1339.  
  1340.   end = ZV;
  1341.  
  1342.   startp = new_screen->contents[vpos] + XFASTINT (w->left);
  1343.   endp = startp + width;
  1344.  
  1345.   /* Loop generating characters.
  1346.    Stop at end of buffer, before newline,
  1347.    or if reach or pass continuation column.  */
  1348.  
  1349.   pause = pos;
  1350.   while (p1 < endp)
  1351.     {
  1352. restart:
  1353.       p1prev = p1;
  1354.       if (pos == pause)
  1355.     {
  1356.       if (pos == end)
  1357.         break;
  1358.       if (pos == point && point_vpos < 0)
  1359.         {
  1360.           point_vpos = vpos;
  1361.           point_hpos = p1 - startp;
  1362.         }
  1363.  
  1364.       pause = end;
  1365.       if (pos < point && point < pause)
  1366.         pause = point;
  1367.       if (pos < GPT && GPT < pause)
  1368.         pause = GPT;
  1369.  
  1370.       p = &FETCH_CHAR (pos);
  1371.     }
  1372.       c = *p++;
  1373. #ifdef EIGHT_BIT
  1374.       if (visible[c])
  1375. #else
  1376.       if (c >= 040 && c < 0177)
  1377. #endif
  1378.       /* This optimises the frequent part (displayable characters) of
  1379.      this inner loop. If the conditions aren't met, return to old
  1380.      inner loop. */
  1381.         {
  1382.       if (p1 >= startp)
  1383.         {
  1384.           do
  1385.             {
  1386.           *p1++ = c;
  1387.           pos++;
  1388.           if (p1 >= endp)
  1389.             {
  1390.               p1prev = p1 - 1;
  1391.               goto done;
  1392.             }
  1393.           if (pos == pause) goto restart;
  1394.           c = *p++;
  1395.             }
  1396. #ifdef EIGHT_BIT
  1397.           while (visible[c]);
  1398. #else
  1399.           while (c >= 040 && c < 0177);
  1400. #endif
  1401.           p1prev = p1;
  1402.         }
  1403.       else
  1404.         {
  1405.           p1++;
  1406.           pos++;
  1407.           goto restart;
  1408.         }
  1409.         }
  1410.       if (c == '\n')
  1411.     {
  1412.       invis = 0;
  1413.       while (pos < end
  1414.          && selective > 0
  1415.          && position_indentation (pos + 1) >= selective)
  1416.         {
  1417.           invis = 1;
  1418.           pos = find_next_newline (pos + 1, 1);
  1419.           if (FETCH_CHAR (pos - 1) == '\n')
  1420.         pos--;
  1421.         }
  1422.       if (invis && selective_e)
  1423.         {
  1424.           p1 += 4;
  1425.           if (p1 - startp > width)
  1426.         p1 = endp;
  1427.           if (p1prev >= startp)
  1428.         strncpy (p1prev, " ...", p1 - p1prev);
  1429.         }
  1430.       break;
  1431.     }
  1432.       else if (c == '\t')
  1433.     {
  1434.       do
  1435.         {
  1436.           if (p1 >= startp && p1 < endp)
  1437.         *p1 = ' ';
  1438.           p1++;
  1439.         }
  1440.       while ((p1 - startp + taboffset + hscroll - (hscroll > 0))
  1441.          % tab_width);
  1442.     }
  1443.       else if (c == Ctl ('M') && selective == -1)
  1444.     {
  1445.       pos = find_next_newline (pos, 1);
  1446.       if (FETCH_CHAR (pos - 1) == '\n')
  1447.         pos--;
  1448.       if (selective_e)
  1449.         {
  1450.           p1 += 4;
  1451.           if (p1 - startp > width)
  1452.         p1 = endp;
  1453.           if (p1prev >= startp)
  1454.         strncpy (p1prev, " ...", p1 - p1prev);
  1455.         }
  1456.       break;
  1457.     }
  1458.       else if (c < 0200 && ctl_arrow)
  1459.     {
  1460.       if (p1 >= startp)
  1461.         *p1 = '^';
  1462.       p1++;
  1463.       if (p1 >= startp && p1 < endp)
  1464.         *p1 = c ^ 0100;
  1465.       p1++;
  1466.     }
  1467.       else
  1468.     {
  1469.       if (p1 >= startp)
  1470.         *p1 = '\\';
  1471.       p1++;
  1472.       if (p1 >= startp && p1 < endp)
  1473.         *p1 = (c >> 6) + '0';
  1474.       p1++;
  1475.       if (p1 >= startp && p1 < endp)
  1476.         *p1 = (7 & (c >> 3)) + '0';
  1477.       p1++;
  1478.       if (p1 >= startp && p1 < endp)
  1479.         *p1 = (7 & c) + '0';
  1480.       p1++;
  1481.     }
  1482.       pos++;
  1483.     }
  1484. done:
  1485.  
  1486.   val.hpos = - XINT (w->hscroll);
  1487.   if (val.hpos)
  1488.     val.hpos++;
  1489.  
  1490.   val.vpos = 1;
  1491.  
  1492.   lastpos = pos;
  1493.  
  1494.   /* Handle continuation in middle of a character */
  1495.   /* by backing up over it */
  1496.   if (p1 > endp)
  1497.     {
  1498.       /* Start the next line with that same character */
  1499.       pos--;
  1500.       /* but at a negative hpos, to skip the columns output on this line.  */
  1501.       val.hpos += p1prev - endp;
  1502.       /* Keep in this line everything up to the continuation column.  */
  1503.       p1 = endp;
  1504.     }
  1505.  
  1506.   /* Finish deciding which character to start the next line on,
  1507.      and what hpos to start it at.
  1508.      Also set `lastpos' to the last position which counts as "on this line"
  1509.      for cursor-positioning.  */
  1510.  
  1511.   if (pos < ZV)
  1512.     {
  1513.       if (FETCH_CHAR (pos) == '\n')
  1514.     /* If stopped due to a newline, start next line after it */
  1515.     pos++;
  1516.       else
  1517.     /* Stopped due to right margin of window */
  1518.     {
  1519.       if (truncate)
  1520.         {
  1521.           *p1++ = '$';
  1522.           /* Truncating => start next line after next newline,
  1523.          and point is on this line if it is before the newline,
  1524.          and skip none of first char of next line */
  1525.           pos = find_next_newline (pos, 1);
  1526.           val.hpos = XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0;
  1527.  
  1528.           lastpos = pos - (FETCH_CHAR (pos - 1) == '\n');
  1529.         }
  1530.       else
  1531.         {
  1532.           *p1++ = '\\';
  1533.           val.vpos = 0;
  1534.           lastpos--;
  1535.         }
  1536.     }
  1537.     }
  1538.  
  1539.   /* If point is at eol or in invisible text at eol,
  1540.      record its screen location now.  */
  1541.  
  1542.   if (start <= point && point <= lastpos && point_vpos < 0)
  1543.     {
  1544.       point_vpos = vpos;
  1545.       point_hpos = p1 - startp;
  1546.     }
  1547.  
  1548.   if (point_vpos == vpos)
  1549.     {
  1550.       if (point_hpos < 0) point_hpos = 0;
  1551.       if (point_hpos > width) point_hpos = width;
  1552.       point_hpos += XFASTINT (w->left);
  1553.       if (w == XWINDOW (selected_window))
  1554.     {
  1555.       cursor_vpos = point_vpos;
  1556.       cursor_hpos = point_hpos;
  1557.  
  1558.       /* Line is not continued and did not start in middle of character */
  1559.       if (hpos == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)
  1560.           && val.vpos)
  1561.         {
  1562.           this_line_bufpos = start;
  1563.           this_line_buffer = current_buffer;
  1564.           this_line_vpos = point_vpos;
  1565.           this_line_start_hpos = hpos;
  1566.           this_line_endpos = Z - lastpos;
  1567.         }
  1568.       else
  1569.         this_line_bufpos = 0;
  1570.     }
  1571.     }
  1572.   /* Save positions of all lines of current window */
  1573.   if (w == XWINDOW(selected_window) && vpos < MAX_WIN_LINE)
  1574.   {
  1575.       /* Line is not continued and did not start in middle of character */
  1576.       if (hpos == (XINT (w->hscroll) ? 1 - XINT (w->hscroll) : 0)
  1577.       && val.vpos)
  1578.       {
  1579.       if (current_buffer != win_line_buffer ||
  1580.           !(win_line_modified >= MODIFF))
  1581.       {
  1582.           win_line_buffer = current_buffer;
  1583.           win_line_modified = MODIFF;
  1584.           bzero(win_line_bufpos, sizeof win_line_bufpos);
  1585.       }
  1586.       win_line_bufpos[vpos - XINT (w->top)] = start;
  1587.       }
  1588.       else
  1589.       win_line_bufpos[vpos - XINT (w->top)] = 0;
  1590.   }
  1591.  
  1592.   /* If hscroll and line not empty, insert truncation-at-left marker */
  1593.   if (hscroll && lastpos != start)
  1594.     {
  1595.       *startp = '$';
  1596.       if (p1 <= startp)
  1597.     p1 = startp + 1;
  1598.     }
  1599.  
  1600.   if (XFASTINT (w->width) + XFASTINT (w->left) != screen_width)
  1601.     {
  1602.       endp++;
  1603.       if (p1 < startp) p1 = startp;
  1604.       while (p1 < endp) *p1++ = ' ';
  1605.       *p1++ = '|';
  1606.     }
  1607.   new_screen->used[vpos] = max (new_screen->used[vpos],
  1608.                 p1 - new_screen->contents[vpos]);
  1609.   new_screen->contents[vpos][new_screen->used[vpos]] = 0;
  1610.  
  1611.   /* If the start of this line is the overlay arrow-position,
  1612.      then put the arrow string into the display-line.  */
  1613.  
  1614.   if (XTYPE (Voverlay_arrow_position) == Lisp_Marker
  1615.       && current_buffer == XMARKER (Voverlay_arrow_position)->buffer
  1616.       && start == marker_position (Voverlay_arrow_position)
  1617.       && XTYPE (Voverlay_arrow_string) == Lisp_String)
  1618.     {
  1619.       unsigned char *p = XSTRING (Voverlay_arrow_string)->data;
  1620.       int len = XSTRING (Voverlay_arrow_string)->size;
  1621.       if (len > XFASTINT (w->width) - 1)
  1622.     len = XFASTINT (w->width) - 1;
  1623.       bcopy (p, startp, len);
  1624.       if (new_screen->used[vpos] < len + startp - new_screen->contents[vpos])
  1625.     new_screen->used[vpos] = len + startp - new_screen->contents[vpos];
  1626.     }
  1627.  
  1628.   val.bufpos = pos;
  1629.   val_display_text_line = val;
  1630.   return &val_display_text_line;
  1631. }
  1632.  
  1633. /* Display the mode line for window w */
  1634.  
  1635. display_mode_line (w)
  1636.      struct window *w;
  1637. {
  1638.   register int vpos = XFASTINT (w->height) + XFASTINT (w->top) - 1;
  1639.   register int left = XFASTINT (w->left);
  1640.   register int right = XFASTINT (w->width) + left;
  1641.   get_display_line (vpos, left);
  1642.  
  1643.   display_mode_element (w, vpos, left, 0, right, right,
  1644.             current_buffer->mode_line_format);
  1645.  
  1646.   /* Make the mode line inverse video if the entire line
  1647.      is made of mode lines.
  1648.      I.e. if this window is full width,
  1649.      or if it is the child of a full width window
  1650.      (which implies that that window is split side-by-side
  1651.      and the rest of this line is mode lines of the sibling windows).  */
  1652.   if (XFASTINT (w->width) == screen_width ||
  1653.       XFASTINT (XWINDOW (w->parent)->width) == screen_width)
  1654.     new_screen->highlight[vpos] = mode_line_inverse_video;
  1655.  
  1656. }
  1657.  
  1658. /* Contribute ELT to the mode line for window W.
  1659.    How it translates into text depends on its data type.
  1660.  
  1661.    LINE is the display-line that the mode line is being displayed in.
  1662.  
  1663.    HPOS is the position (absolute on screen) where this element's text
  1664.    should start.  The output is truncated automatically at the right
  1665.    edge of window W.
  1666.  
  1667.    DEPTH is the depth in recursion.  It is used to prevent
  1668.    infinite recursion here.
  1669.  
  1670.    MINENDCOL is the hpos before which the element may not end.
  1671.    The element is padded at the right with spaces if nec
  1672.    to reach this column.
  1673.  
  1674.    MAXENDCOL is the hpos past which this element may not extend.
  1675.    If MINENDCOL is > MAXENDCOL, MINENDCOL takes priority.
  1676.    (This is necessary to make nested padding and truncation work.)
  1677.  
  1678.    Returns the hpos of the end of the text generated by ELT.
  1679.    The next element will receive that value as its HPOS arg,
  1680.    so as to concatenate the elements.  */
  1681.  
  1682. int
  1683. display_mode_element (w, vpos, hpos, depth, minendcol, maxendcol, elt)
  1684.      struct window *w;
  1685.      int vpos;
  1686.      register int hpos;
  1687.      int depth;
  1688.      int minendcol;
  1689.      register int maxendcol;
  1690.      register Lisp_Object elt;
  1691. {
  1692.  tail_recurse:
  1693.   if (depth > 10)
  1694.     goto invalid;
  1695.  
  1696.   depth++;
  1697.  
  1698. #ifdef SWITCH_ENUM_BUG
  1699.   switch ((int) XTYPE (elt))
  1700. #else
  1701.   switch (XTYPE (elt))
  1702. #endif
  1703.     {
  1704.     case Lisp_String:
  1705.       {
  1706.     /* A string: output it and check for %-constructs within it.  */
  1707.     register unsigned char c;
  1708.     register unsigned char *this = XSTRING (elt)->data;
  1709.  
  1710.     while (hpos < maxendcol && *this)
  1711.       {
  1712.         unsigned char *last = this;
  1713.         while ((c = *this++) != '\0' && c != '%')
  1714.           ;
  1715.         if (this - 1 != last)
  1716.           {
  1717.         register int lim = --this - last + hpos;
  1718.         hpos = display_string (w, vpos, last, hpos, 0, hpos,
  1719.                        min (lim, maxendcol));
  1720.           }
  1721.         else /* c == '%' */
  1722.           {
  1723.         register int spec_width = 0;
  1724.  
  1725.         /* We can't allow -ve args due to the "%-" construct */
  1726.         /* Argument specifies minwidth but not maxwidth
  1727.            (maxwidth can be specified by
  1728.              (<negative-number> . <stuff>) mode-line elements) */
  1729.  
  1730.         while ((c = *this++) >= '0' && c <= '9')
  1731.           {
  1732.             spec_width = spec_width * 10 + (c - '0');
  1733.           }
  1734.  
  1735.         spec_width += hpos;
  1736.         if (spec_width > maxendcol)
  1737.           spec_width = maxendcol;
  1738.  
  1739.         if (c == 'M')
  1740.           hpos = display_mode_element (w, vpos, hpos, depth,
  1741.                            spec_width, maxendcol,
  1742.                            Vglobal_mode_string);
  1743.         else if (c != 0)
  1744.           hpos = display_string (w, vpos,
  1745.                      decode_mode_spec (w, c,
  1746.                                spec_width - hpos),
  1747.                      hpos, 0, spec_width, maxendcol);
  1748.           }
  1749.       }
  1750.       }
  1751.       break;
  1752.  
  1753.     case Lisp_Symbol:
  1754.       /* A symbol: process the value of the symbol recursively
  1755.      as if it appeared here directly.  Avoid error if symbol void.
  1756.      Special case: if value of symbol is a string, output the string
  1757.      literally.  */
  1758.       {
  1759.     register Lisp_Object tem;
  1760.     tem = Fboundp (elt);
  1761.     if (!NULL (tem))
  1762.       {
  1763.         tem = Fsymbol_value (elt);
  1764.         /* If value is a string, output that string literally:
  1765.            don't check for % within it.  */
  1766.         if (XTYPE (tem) == Lisp_String)
  1767.           hpos = display_string (w, vpos, XSTRING (tem)->data,
  1768.                      hpos, 0, minendcol, maxendcol);
  1769.         /* Give up right away for nil or t.  */
  1770.         else if (!EQ (tem, elt))
  1771.           { elt = tem; goto tail_recurse; }
  1772.       }
  1773.       }
  1774.       break;
  1775.  
  1776.     case Lisp_Cons:
  1777.       {
  1778.     register Lisp_Object car, tem;
  1779.  
  1780.     /* A cons cell: three distinct cases.
  1781.        If first element is a string or a cons, process all the elements
  1782.        and effectively concatenate them.
  1783.        If first element is a negative number, truncate displaying cdr to
  1784.        at most that many characters.  If positive, pad (with spaces)
  1785.        to at least that many characters.
  1786.        If first element is a symbol, process the cadr or caddr recursively
  1787.        according to whether the symbol's value is non-nil or nil.  */
  1788.     car = XCONS (elt)->car;
  1789.     if (XTYPE (car) == Lisp_Symbol)
  1790.       {
  1791.         tem = Fboundp (car);
  1792.         elt = XCONS (elt)->cdr;
  1793.         if (XTYPE (elt) != Lisp_Cons)
  1794.           goto invalid;
  1795.         /* elt is now the cdr, and we know it is a cons cell.
  1796.            Use its car if CAR has a non-nil value.  */
  1797.         if (!NULL (tem))
  1798.           {
  1799.         tem = Fsymbol_value (car);
  1800.         if (!NULL (tem))
  1801.           { elt = XCONS (elt)->car; goto tail_recurse; }
  1802.           }
  1803.         /* Symbol's value is nil (or symbol is unbound)
  1804.            Get the cddr of the original list
  1805.            and if possible find the caddr and use that.  */
  1806.         elt = XCONS (elt)->cdr;
  1807.         if (NULL (elt))
  1808.           break;
  1809.         else if (XTYPE (elt) != Lisp_Cons)
  1810.           goto invalid;
  1811.         elt = XCONS (elt)->car;
  1812.         goto tail_recurse;
  1813.       }
  1814.     else if (XTYPE (car) == Lisp_Int)
  1815.       {
  1816.         register int lim = XINT (car);
  1817.         elt = XCONS (elt)->cdr;
  1818.         if (lim < 0)
  1819.           /* Negative int means reduce maximum width.
  1820.          DO NOT change MINENDCOL here!
  1821.          (20 -10 . foo) should truncate foo to 10 col
  1822.          and then pad to 20.  */
  1823.           maxendcol = min (maxendcol, hpos - lim);
  1824.         else if (lim > 0)
  1825.           {
  1826.         /* Padding specified.  Don't let it be more than
  1827.            current maximum.  */
  1828.         lim += hpos;
  1829.         if (lim > maxendcol)
  1830.           lim = maxendcol;
  1831.         /* If that's more padding than already wanted, queue it.
  1832.            But don't reduce padding already specified even if
  1833.            that is beyond the current truncation point.  */
  1834.         if (lim > minendcol)
  1835.           minendcol = lim;
  1836.           }
  1837.         goto tail_recurse;
  1838.       }
  1839.     else if (XTYPE (car) == Lisp_String || XTYPE (car) == Lisp_Cons)
  1840.       {
  1841.         register int limit = 50;
  1842.         /* LIMIT is to protect against circular lists.  */
  1843.         while (XTYPE (elt) == Lisp_Cons && --limit > 0
  1844.            && hpos < maxendcol)
  1845.           {
  1846.         hpos = display_mode_element (w, vpos, hpos, depth,
  1847.                          hpos, maxendcol,
  1848.                          XCONS (elt)->car);
  1849.         elt = XCONS (elt)->cdr;
  1850.           }
  1851.       }
  1852.       }
  1853.       break;
  1854.  
  1855.     default:
  1856.     invalid:
  1857.       return (display_string (w, vpos, "*invalid*", hpos, 0,
  1858.                   minendcol, maxendcol));
  1859.     }
  1860.  
  1861.  end:
  1862.   if (minendcol > hpos)
  1863.     hpos = display_string (w, vpos, "", hpos, 0, minendcol, -1);
  1864.   return hpos;
  1865. }
  1866.  
  1867. /* Return a string for the output of a mode line %-spec
  1868.    for window W, generated by character C and width MAXWIDTH.  */
  1869.  
  1870. char *
  1871. decode_mode_spec (w, c, maxwidth)
  1872.      struct window *w;
  1873.      register char c;
  1874.      register int maxwidth;
  1875. {
  1876.   Lisp_Object obj = Qnil;
  1877.   char *decode_mode_spec_buf = (char *) temp_screen->total_contents;
  1878.  
  1879.   switch (c)
  1880.     {
  1881.     case 'b': 
  1882.       obj = current_buffer->name;
  1883. #if 0
  1884.       if (maxwidth >= 3 && XSTRING (obj)->size > maxwidth)
  1885.     {
  1886.       bcopy (XSTRING (obj)->data, decode_mode_spec_buf, maxwidth - 1);
  1887.       decode_mode_spec_buf[maxwidth - 1] = '\\';
  1888.       decode_mode_spec_buf[maxwidth] = '\0';
  1889.       return decode_mode_spec_buf;
  1890.     }
  1891. #endif
  1892.       break;
  1893.  
  1894.     case 'f': 
  1895.       obj = current_buffer->filename;
  1896. #if 0
  1897.       if (XTYPE (obj) == Lisp_String && XSTRING (obj)->size > maxwidth)
  1898.     {
  1899.       bcopy ("...", decode_mode_spec_buf, 3);
  1900.       bcopy (XSTRING (obj)->data + XSTRING (obj)->size - maxwidth + 3,
  1901.          decode_mode_spec_buf + 3, maxwidth - 3);
  1902.       return decode_mode_spec_buf;
  1903.     }
  1904. #endif
  1905.       break;
  1906.  
  1907.     case 'm': 
  1908.       obj = current_buffer->mode_name;
  1909.       break;
  1910.  
  1911.     case 'n':
  1912.       if (BEGV > BEG || ZV < Z)
  1913.     return " Narrow";
  1914.       break;
  1915.  
  1916.     case '*':
  1917.       if (!NULL (current_buffer->read_only))
  1918.     return "%";
  1919.       if (MODIFF > current_buffer->save_modified)
  1920.     return "*";
  1921.       return "-";
  1922.  
  1923.     case 's':
  1924.       /* status of process */
  1925. #ifdef subprocesses
  1926.       obj = Fget_buffer_process (Fcurrent_buffer ());
  1927.       if (NULL (obj))
  1928.     return "no process";
  1929.       obj = Fsymbol_name (Fprocess_status (obj));
  1930.       break;
  1931. #else
  1932.       return "no processes";
  1933. #endif /* subprocesses */
  1934.  
  1935.     case 'p':
  1936.       {
  1937.     int pos = marker_position (w->start);
  1938.     int total = ZV - BEGV;
  1939.  
  1940.     if (XFASTINT (w->window_end_pos) <= Z - ZV)
  1941.       {
  1942.         if (pos <= BEGV)
  1943.           return "All";
  1944.         else
  1945.           return "Bottom";
  1946.       }
  1947.     else if (pos <= BEGV)
  1948.       return "Top";
  1949.     else
  1950.       {
  1951.         total = ((pos - BEGV) * 100 + total - 1) / total;
  1952.         /* We can't normally display a 3-digit number,
  1953.            so get us a 2-digit number that is close.  */
  1954.         if (total == 100)
  1955.           total = 99;
  1956.         sprintf (decode_mode_spec_buf, "%2d%%", total);
  1957.         return decode_mode_spec_buf;
  1958.       }
  1959.       }
  1960.  
  1961.     case '[': 
  1962.       {
  1963.     int i;
  1964.     char *p;
  1965.     if (command_loop_level > 5)
  1966.       return "[[[... ";
  1967.     p = decode_mode_spec_buf;
  1968.     for (i = 0; i < command_loop_level; i++)
  1969.       *p++ = '[';
  1970.     *p = 0;
  1971.     return decode_mode_spec_buf;
  1972.       }
  1973.  
  1974.     case '%':
  1975.       return "%";
  1976.  
  1977.     case ']': 
  1978.       {
  1979.     int i;
  1980.     char *p;
  1981.     if (command_loop_level > 5)
  1982.       return " ...]]]";
  1983.     p = decode_mode_spec_buf;
  1984.     for (i = 0; i < command_loop_level; i++)
  1985.       *p++ = ']';
  1986.     *p = 0;
  1987.     return decode_mode_spec_buf;
  1988.       }
  1989.  
  1990.     case '-':
  1991.       {
  1992.     int i;
  1993.     if (maxwidth < 140)
  1994.       return "--------------------------------------------------------------------------------------------------------------------------------------------";
  1995.     for (i = 0; i < maxwidth; i++)
  1996.       decode_mode_spec_buf[i] = '-';
  1997.     return decode_mode_spec_buf;
  1998.       }
  1999.     }
  2000.  
  2001.   if (XTYPE (obj) == Lisp_String)
  2002.     return (char *) XSTRING (obj)->data;
  2003.   else
  2004.     return "";
  2005. }
  2006.  
  2007. /* Display STRING on one line of window W, starting at HPOS.
  2008.    Display at position VPOS.  Caller should do get_display_line first.
  2009.  
  2010.   TRUNCATE is character to display at end if truncated.  Zero for none.
  2011.  
  2012.   MINCOL is the first column ok to end at.  (Pad with spaces to this col.)
  2013.   MAXCOL is the last column ok to end at.  Truncate here.
  2014.     -1 for MINCOL or MAXCOL means no explicit minimum or maximum.
  2015.   Both count from the left edge of the screen, as does HPOS.
  2016.   The right edge of W is an implicit maximum.
  2017.   If TRUNCATE is nonzero, the implicit maximum is one column before the edge.
  2018.  
  2019.   Returns ending hpos */
  2020.  
  2021. display_string (w, vpos, string, hpos, truncate, mincol, maxcol)
  2022.      struct window *w;
  2023.      int vpos;
  2024.      unsigned char *string;
  2025.      int hpos;
  2026.      char truncate;
  2027.      int mincol, maxcol;
  2028. {
  2029.   register int c;
  2030.   register unsigned char *p1;
  2031.   int hscroll = XINT (w->hscroll);
  2032.   int tab_width = XINT (current_buffer->tab_width);
  2033.   register unsigned char *start;
  2034.   register unsigned char *end;
  2035.   unsigned char *p1start = new_screen->contents[vpos] + hpos;
  2036.   int window_width = XFASTINT (w->width);
  2037.  
  2038.   if (tab_width <= 0 || tab_width > 20) tab_width = 8;
  2039.  
  2040.   p1 = p1start;
  2041.   start = new_screen->contents[vpos] + XFASTINT (w->left);
  2042.   end = start + window_width - (truncate != 0);
  2043.  
  2044.   if ((window_width + XFASTINT (w->left)) != screen_width)
  2045.     *end-- = '|';
  2046.  
  2047.   if (maxcol >= 0 && end - new_screen->contents[vpos] > maxcol)
  2048.     end = new_screen->contents[vpos] + maxcol;
  2049.   if (maxcol >= 0 && mincol > maxcol)
  2050.     mincol = maxcol;
  2051.  
  2052.   while (p1 < end)
  2053.     {
  2054.       c = *string++;
  2055.       if (!c) break;
  2056. #ifdef EIGHT_BIT
  2057.       if (visible[c])
  2058. #else
  2059.       if (c >= 040 && c < 0177)
  2060. #endif
  2061.     {
  2062.       if (p1 >= start)
  2063.         *p1 = c;
  2064.       p1++;
  2065.     }
  2066.       else if (c == '\t')
  2067.     {
  2068.       do
  2069.         {
  2070.           if (p1 >= start && p1 < end)
  2071.         *p1 = ' ';
  2072.           p1++;
  2073.         }
  2074.       while ((p1 - start + hscroll - (hscroll > 0)) % tab_width);
  2075.     }
  2076.       else if (c < 0200 && buffer_defaults.ctl_arrow)
  2077.     {
  2078.       if (p1 >= start)
  2079.         *p1 = '^';
  2080.       p1++;
  2081.       if (p1 >= start && p1 < end)
  2082.         *p1 = c ^ 0100;
  2083.       p1++;
  2084.     }
  2085.       else
  2086.     {
  2087.       if (p1 >= start)
  2088.         *p1 = '\\';
  2089.       p1++;
  2090.       if (p1 >= start && p1 < end)
  2091.         *p1 = (c >> 6) + '0';
  2092.       p1++;
  2093.       if (p1 >= start && p1 < end)
  2094.         *p1 = (7 & (c >> 3)) + '0';
  2095.       p1++;
  2096.       if (p1 >= start && p1 < end)
  2097.         *p1 = (7 & c) + '0';
  2098.       p1++;
  2099.     }
  2100.     }
  2101.  
  2102.   if (c)
  2103.     {
  2104.       p1 = end;
  2105.       if (truncate) *p1++ = truncate;
  2106.     }
  2107.   else if (mincol >= 0)
  2108.     {
  2109.       end = new_screen->contents[vpos] + mincol;
  2110.       while (p1 < end)
  2111.     *p1++ = ' ';
  2112.     }
  2113.  
  2114.   {
  2115.     register int len = p1 - new_screen->contents[vpos];
  2116.     if (len > new_screen->used[vpos])
  2117.       new_screen->used[vpos] = len;
  2118.     new_screen->contents[vpos][new_screen->used[vpos]] = 0;
  2119.     return len;
  2120.   }
  2121. }
  2122.  
  2123. syms_of_xdisp ()
  2124. {
  2125.   staticpro (&last_arrow_position);
  2126.   staticpro (&last_arrow_string);
  2127.   last_arrow_position = Qnil;
  2128.   last_arrow_string = Qnil;
  2129.  
  2130.   DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string,
  2131.     "String displayed by mode-line-format's \"%m\" specifiation.");
  2132.   Vglobal_mode_string = Qnil;
  2133.  
  2134.   DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position,
  2135.     "Marker for where to display an arrow on top of the buffer text.\n\
  2136. This must be the beginning of a line in order to work.\n\
  2137. See also overlay-arrow-string.");
  2138.   Voverlay_arrow_position = Qnil;
  2139.  
  2140.   DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string,
  2141.     "String to display as an arrow.  See also overlay-arrow-position.");
  2142.   Voverlay_arrow_string = Qnil;
  2143.  
  2144.   DEFVAR_INT ("scroll-step", &scroll_step,
  2145.     "*The number of lines to try scrolling a window by when point moves out.\n\
  2146. If that fails to bring point back on screen, point is centered instead.\n\
  2147. If this is zero, point is always centered after it moves off screen.");
  2148.  
  2149.   DEFVAR_BOOL ("reset-terminal-on-clear", &reset_terminal_on_clear,
  2150.     "Non-nil means re-init terminal modes for clear screen as on entry to Emacs.");
  2151.   reset_terminal_on_clear = 1;
  2152.  
  2153.   DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask");
  2154.  
  2155.   DEFVAR_BOOL ("truncate-partial-width-windows",
  2156.            &truncate_partial_width_windows,
  2157.     "*Non-nil means truncate lines in all windows less than full screen wide.");
  2158.   truncate_partial_width_windows = 1;
  2159.  
  2160.   DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video,
  2161.     "*Non-nil means use inverse video, or other suitable display mode, for the mode line.");
  2162.   mode_line_inverse_video = 1;
  2163.  
  2164.   defsubr (&Sredraw_display);
  2165. }
  2166.  
  2167. /* initialize the window system */
  2168. init_xdisp ()
  2169. {
  2170.   Lisp_Object root_window;
  2171. #ifndef COMPILER_REGISTER_BUG
  2172.   register
  2173. #endif COMPILER_REGISTER_BUG
  2174.     struct window *mini_w;
  2175. #ifdef EIGHT_BIT
  2176.   int i;
  2177. #endif
  2178.  
  2179.   CLEAR_WIN_LINE();
  2180.   this_line_bufpos = 0;
  2181.  
  2182.   mini_w = XWINDOW (minibuf_window);
  2183.   root_window = mini_w->prev;
  2184.  
  2185.   echo_area_contents = 0;
  2186.   prev_echo_area_contents = 0;
  2187.  
  2188.   if (!noninteractive)
  2189.     {
  2190.       XFASTINT (XWINDOW (root_window)->top) = 0;
  2191.       set_window_height (root_window, screen_height - 1, 0);
  2192.       XFASTINT (mini_w->top) = screen_height - 1;
  2193.       set_window_height (minibuf_window, 1, 0);
  2194.  
  2195.       XFASTINT (XWINDOW (root_window)->width) = screen_width;
  2196.       XFASTINT (mini_w->width) = screen_width;
  2197.     }
  2198. #ifdef EIGHT_BIT
  2199.   for (i = 040; i < 0177; i++) visible[i] = 1;
  2200. #ifdef AMIGA
  2201.   for (i = 0240; i <= 0377; i++) visible[i] = 1;
  2202. #endif
  2203. #endif
  2204. }
  2205.